package com.kingdee.hackson.utils;

import com.fasterxml.jackson.databind.ser.Serializers;

public class Base39Utils {
    private static final char[] CHARS = "+/0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
    private static final int RADIX;
    private static final int[] VALUES;

    public static long toLong(String s) {
        try {
            long e = 0L;
            char[] arg3 = s.toCharArray();
            int arg4 = arg3.length;

            for (int arg5 = 0; arg5 < arg4; ++arg5) {
                char ch = arg3[arg5];
                int vch = VALUES[ch];
                if (vch == -1) {
                    throw new IllegalArgumentException("ID " + s + " has unreconized character: " + ch);
                }
                e = e * (long) RADIX + (long) vch;
            }

            return e;
        } catch (IndexOutOfBoundsException arg7) {
            throw new IllegalArgumentException("ID " + s + " has unreconized character", arg7);
        }
    }

    public static String toString(long v) {
        StringBuilder sb = new StringBuilder(12);

        do {
            sb.append(CHARS[(int) (v % (long) RADIX)]);
            v /= (long) RADIX;
        } while (v != 0L);

        return sb.reverse().toString();
    }

    static {
        RADIX = CHARS.length;
        VALUES = new int[CHARS[RADIX - 1] + 1];

        int i;
        for (i = 0; i < CHARS[RADIX - 1]; ++i) {
            VALUES[i] = -1;
        }

        i = 0;
        char[] arg0 = CHARS;
        int arg1 = arg0.length;

        for (int arg2 = 0; arg2 < arg1; ++arg2) {
            char ch = arg0[arg2];
            VALUES[ch] = i++;
        }

    }

    public static void main(String[] args) {
        String s = Base39Utils.toString(931172299174842368L);
        System.out.println(s);
        long l = Base39Utils.toLong("0XC4KIRA97H6");
        System.out.println(l);
    }
}